import {del, get, post} from "@/api/base/http";
import {ApiUri} from "@/api/base/ApiPath";

let ApiPath = new ApiUri();

export class Device {
    static Gets = () => {
        return get(ApiPath.Device.LIST);
    }

    static Get = (DeviceId: number) => {
        return get(ApiPath.Device.ROOT + DeviceId);
    }

    static Save = (DriveInfo: object) => {
        return post(ApiPath.Device.ROOT, DriveInfo)
    }

    static Delete = (Id: number) => {
        return del(ApiPath.Device.ROOT + Id)
    }

    static GetPlcAddress = (DriverType: string) => {
        return get(ApiPath.Device.GET_PLC_ADDRESS + DriverType);
    }

    static GetPlcAddressByDriverId = (DriverId: number) => {
        return get(ApiPath.Device.GET_PLC_ADDRESS_BY + DriverId);
    }

    static UpdateAddress = (Address: object) => {
        return post(ApiPath.Device.GET_PLC_ADDRESS_SAVE, Address);
    }

    static DeleteAddress = (Id: number) => {
        return del(ApiPath.Device.GET_PLC_ADDRESS + Id);
    }

    static GetAddress = (Id: number) => {
        return del(ApiPath.Device.GET_PLC_ADDRESS_ID + Id);
    }

    static SynchronizationData = (DeviceType: string, DeviceId: number) => {
        return get(ApiPath.Device.SYNCHRONIZATION_DATA + DeviceType + '/' + DeviceId);
    }

    static SendMessage = (ServerId: number, ClientIndex: number, Message: string) => {
        return post(ApiPath.Device.SEND_MESSAGE, {ServerId: ServerId, ClientIndex: ClientIndex, Message: Message});
    }

    static GetSocketConnectedClients = (ServerId: number) => {
        return get(ApiPath.Device.SOCKET_CLIENTS, {ServerId: ServerId});
    }
}
